public class UnionFind {
    private int[] root=null;

    public static void main(String[] args) {
        UnionFind unionFind = new UnionFind();
        unionFind.union(2,3);
        int i = unionFind.find(2);
        System.out.println(i);
    }

    public UnionFind(){
        root = new int[6];
        for (int i = 0;i < 6; i++){
            root[i] = i;
        }
    }

    public int find(int x){
        if(x==root[x]){
            return root[x];
        }
        return find(root[x]);
    }

    public void union(int x,int y){
        int rootX = find(x);
        int rootY = find(y);
        if (rootX != rootY){
            root[rootX]=rootY;
        }
    }
}
